package io.renren.sf.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.sf.entity.CbBrushEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.sf.entity.CbContrastEntity;
import io.renren.sf.service.CbContrastService;
import io.renren.common.utils.R;



/**
 *
 *
 * @author cyl_txw
 * @email cyl_txw@gmail.com
 * @date 2021-04-08 23:20:11
 */
@RestController
@RequestMapping("sf/cbcontrast")
public class CbContrastController {
    @Autowired
    private CbContrastService cbContrastService;

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("sf:cbcontrast:info")
    public R info(@PathVariable("id") Long id){
		CbContrastEntity cbContrast = cbContrastService.getById(id);

        return R.ok().put("cbContrast", cbContrast);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("sf:cbcontrast:save")
    public R save(@RequestBody CbContrastEntity cbContrast){
        try {
            cbContrastService.save(cbContrast);
            return R.ok();
        } catch (Exception e) {
            return R.error("该字体已存在对比数据，请刷新页面");
        }
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("sf:cbcontrast:update")
    public R update(@RequestBody CbContrastEntity cbContrast){
		cbContrastService.updateById(cbContrast);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("sf:cbcontrast:delete")
    public R delete(@RequestBody Long[] ids){
		cbContrastService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 通过字体id获取笔法以及笔法图片
     */
    @GetMapping("/getContrastByWordId/{wordId}")
    public R getContrastByWordId(@PathVariable("wordId") Long wordId){
        CbContrastEntity cbContrastEntity = cbContrastService.getContrastByWordId(wordId);
        return R.ok().put("cbContrast", cbContrastEntity);
    }

}
